import java.io.*;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-10
 * Time: 9:47
 */
//InputStream,OutputStream
public class demo2 {
    public static void main1(String[] args) throws IOException {
        File file = new File("./test.txt");
        boolean ok = file.createNewFile();
        System.out.println(ok);
    }

    public static void main2(String[] args) {
        byte[] bytes = new byte[5];
        try (InputStream inputStream = new FileInputStream("./test.txt")) {
            int i = inputStream.read(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String s = new String(bytes);
        System.out.println(s);
    }

    public static void main(String[] args) {
        File file = new File("./test.txt");
        String s = new String(" world");
        byte[] buffer;
        buffer = s.getBytes();//将String变成byte数组

        try (OutputStream outputStream = new FileOutputStream(file, true)) {
            outputStream.write(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
